package model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import javax.imageio.ImageIO;

public class GameObject implements Serializable
{       
        protected int xDim;
        protected int yDim;
        protected Color color;
        protected String filename;
        protected transient BufferedImage image;
        protected Vector2 vector;
        protected boolean movable;
        
        protected final int FIELD_X = 450;
        protected final int FIELD_Y = 650;
        
        public GameObject()
        {
                xDim = 20;
                yDim = 20;
                color = Color.RED;
                filename = "";
                image = null;
                vector = new Vector2();
                movable = false;
        }
        
        public GameObject(int xDim, int yDim, Color c, Vector2 v, boolean m)
        {
                this.xDim = xDim;
                this.yDim = yDim;
                color = c;
                filename = "";
                image = null;
                vector = new Vector2(v);
                movable = m;
        }
        
        public GameObject(int xDim, int yDim, String filename, Vector2 v, boolean m)
        {
                this.xDim = xDim;
                this.yDim = yDim;
                color = Color.RED;
                vector = new Vector2(v);
                movable = m;
                this.filename = filename;
                
                try{
                        image = ImageIO.read(new File(filename));
                } catch(IOException e){ 
                }
        }
        
        public int getDimX()
        {
                return xDim;
        }
        
        public int getDimY()
        {
                return yDim;
        }
        
        public void setDimX(int x)
        {
                xDim = x;
        }
        
        public void setDimY(int y)
        {
                yDim = y;
        }
        
        public void changeColor(Color c)
        {
                color = c;
        }
        
        public Color getColor()
        {
                return color;
        }
        
        public void changeImage(String filename)
        {
                this.filename = filename;
                
                try{
                        image = ImageIO.read(new File(filename));
                } catch(IOException e){ 
                }
        }
        
        public String getFilename()
        {
                return filename;
        }
        
//      public void setMovability(boolean m)
//      {
//              movable = m;
//      }
        
        public boolean isMovable()
        {
                return movable;
        }
        
        public double getX()
        {
                return vector.getX();
        }
        
        public double getY()
        {
                return vector.getY();
        }
        
        public void setX(double x)
        {
                vector.setX(x);
        }
        
        public void setY(double y)
        {
                vector.setY(y);
        }
        
        public Point2 getLocation()
        {
                return vector.getLocation();
        }
        
        public void setLocation(Point2 p)
        {
                vector.setLocation(p);
        }
        
        public void setLocation(double x, double y)
        {
                vector.setLocation(x, y);
        }
        
        public void setComponentX(double x)
        {
                vector.setComponentX(x);
        }
        
        public void setComponentY(double y)
        {
                vector.setComponentY(y);
        }
        
        public double getComponentX()
        {
                return vector.getComponentX();
        }
        
        public double getComponentY()
        {
                return vector.getComponentY();
        }
        
        public Vector2 getVect()
        {
                return vector;
        }
        
        public double getMagnitude()
        {
                return vector.getMagnitude();
        }
        
        public double distance(GameObject o)
        {
                return vector.distance(o.getVect());
        }
        
        public double squaredDistance(GameObject o)
        {
                return vector.squaredDistance(o.getVect());
        }
        
        public double distanceX(GameObject o)
        {
                return vector.distanceX(o.getVect());
        }
        
        public double distanceY(GameObject o)
        {
                return vector.distanceY(o.getVect());
        }
        
        public String toString()
        {
                return "XDim: " + xDim + ", yDim: " + yDim + ", Color: " + color + ", Movable: " + movable;
        }
        
        public void update(){}
        
        public void draw(Graphics page){}
        
}